<template>
  <!-- 轮播图 -->
  <el-carousel :interval="4000" type="card" height="200px">
    <el-carousel-item v-for="picture in pictureList" :key="picture.id" class="carouselItem" @click="clickImg(picture.goodsId)">
      <el-image class="img" style="width: 100%; height: 100%"  :src="picture.url">
        <template #error>
          <div class="image-slot">
            <el-icon><icon-picture /></el-icon>
          </div>
        </template>
      </el-image>
      <div class="copywriting">
        <h4 class="title">{{picture.name}}</h4>
        <el-text truncated>{{picture.description}}</el-text>
      </div>
    </el-carousel-item>
  </el-carousel>
</template>

<script setup>
import {list} from '@/api/picture.js';
import {onMounted, ref} from 'vue';
import { Picture as IconPicture } from '@element-plus/icons-vue'
import { useRouter } from "vue-router";
const pictureList = ref([]);
const router = useRouter();

onMounted(async ()=>{
  const response = await list();
  pictureList.value = response.data.data
})

// 点击轮播图，调整商品页
const clickImg = async(id)=> {
  router.push({path: `/goodsDetils`, query: {goodsId: id}})
}

</script>

<style scoped>
.copywriting {
  display: none;
  width: 100%;
  height: 50%;
  position: absolute;
  background: rgba(163, 153, 153, 0.4);
  bottom: 0;
  left: 0;
  animation-duration: 1s;
}
.el-carousel__item h3 {
  color: #475669;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
  text-align: center;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
</style>